package com.shenzhen.horselive.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.shenzhen.horselive.R;
import com.shenzhen.horselive.beans.NoticeBean;

import java.util.List;

public class NoticeAdapter extends RecyclerView.Adapter {
    List<NoticeBean.DataBean> list;
    Context context;

    public void setList(List<NoticeBean.DataBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public NoticeAdapter(Context context) {
        this.context = context;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context)
                .inflate(R.layout.item_notice, parent, false);

        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ViewHolder   viewHolder = (ViewHolder) holder;
        viewHolder.mTvTitle.setText(list.get(position).getNewsTitle());
        viewHolder.mTvContent.setText(list.get(position).getNewsContent());
        viewHolder.mTvTime.setText(list.get(position).getNewsTimestamp());
    }

    @Override
    public int getItemCount() {
        if (list == null)
            return 0;
        else
            return list.size();
    }


    public
    class ViewHolder extends RecyclerView.ViewHolder {
        public View rootView;
        public ImageView mImgImg;
        public TextView mTvTitle;
        public TextView mTvTime;
        public TextView mTvContent;

        public ViewHolder(View rootView) {
            super(rootView);
            this.rootView = rootView;
            this.mImgImg = (ImageView) rootView.findViewById(R.id.img_img);
            this.mTvTitle = (TextView) rootView.findViewById(R.id.tv_title);
            this.mTvTime = (TextView) rootView.findViewById(R.id.tv_time);
            this.mTvContent = (TextView) rootView.findViewById(R.id.tv_content);
        }

    }
}
